package com.learn.redis.scheduled;

import com.learn.redis.handler.CloudSchedulerTask;
import com.learn.redis.service.AccountService;
import com.xcdh.commons.annotation.XCDHAspect;
import com.xcdh.commons.utils.DateUtils;
import com.xcdh.test.entity.AccountDO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Random;

@Component
public class AccountScheduledTask implements Runnable{

    @Value("${server.port}")
    private Integer port ;
    @Resource
    private AccountService accountService ;


    @Scheduled(cron = "0,10,20,30,40,50 * * * * *")
    @XCDHAspect(CloudSchedulerTask.class)
    public void run() {
        // 定时执行的任务逻辑
        System.out.println("定时任务执行了");
        AccountDO accountDO = new AccountDO();
        accountDO.setBalance(Math.random());
        accountDO.setUserId(new Random().nextInt(1000));
        accountDO.setDesc(port + "::"+ DateUtils.getStringDate());
        accountService.save(accountDO) ;
    }

}
